//
//  WKFaceWatingVC.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/26.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKFaceWatingVC.h"

@interface WKFaceWatingVC ()
@property(nonatomic,strong)UIImageView *bgimgView;
@property(nonatomic,strong)UIImageView *smallcircle;
@property(nonatomic,strong)UIImageView *centrecircle;
@property(nonatomic,strong)UIImageView *bigcircle;
@end

@implementation WKFaceWatingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViews];
}

- (void)initViews{
    
    self.naviBar.title = @"正在匹配";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.bgimgView];
    [self.bgimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(375);
        make.height.mas_equalTo(434);
        make.centerY.mas_equalTo(self.view.mas_centerY);
        make.centerX.mas_equalTo(self.view.mas_centerX);
    }];
    _bgimgView.backgroundColor = [UIColor whiteColor];
    _bgimgView.image = ImageNamed(@"wk_facebgimg");
    
    
    [_bgimgView addSubview:self.smallcircle];
    [self.smallcircle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(344/2);
        make.height.mas_equalTo(295/2);
         make.top.mas_equalTo(124);
        make.centerX.mas_equalTo(self.bgimgView.mas_centerX);
    }];
    _smallcircle.backgroundColor = [UIColor clearColor];
    _smallcircle.image = ImageNamed(@"wk_facesmallcircle");
    
    [_bgimgView addSubview:self.centrecircle];
    [self.centrecircle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(376/2);
        make.height.mas_equalTo(376/2);
        make.top.mas_equalTo(104);
//        make.centerY.mas_equalTo(self.view.mas_centerY);
        make.centerX.mas_equalTo(self.bgimgView.mas_centerX);
    }];
    _centrecircle.backgroundColor = [UIColor clearColor];
    _centrecircle.image = ImageNamed(@"wk_facecentrecircle");

    [_bgimgView addSubview:self.bigcircle];
    [self.bigcircle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(412/2);
        make.height.mas_equalTo(304/2);
//        make.centerY.mas_equalTo(self.view.mas_centerY);
         make.top.mas_equalTo(122);
        make.centerX.mas_equalTo(self.bgimgView.mas_centerX);
    }];
    _bigcircle.backgroundColor = [UIColor clearColor];
    _bigcircle.image = ImageNamed(@"wk_facebigcircle");
    
    
    UILabel *loadingTxLb = [UILabel new];
    loadingTxLb.text = @"正在匹配相似好友";
    loadingTxLb.textAlignment = NSTextAlignmentCenter;
    loadingTxLb.textColor = TitleColor;
    loadingTxLb.font = PFSC_MediumFont(15);
    [_bgimgView addSubview:loadingTxLb];
    [loadingTxLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(15);
        make.bottom.mas_equalTo(-58);
        make.centerX.mas_equalTo(self.bgimgView.mas_centerX);
    }];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self rotateView:_smallcircle iscontrary:NO];
        [self rotateView:_centrecircle iscontrary:YES];
    });
    

    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self rotateView:_bigcircle iscontrary:NO];
    });
    
   
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        [[NSNotificationCenter defaultCenter]postNotificationName:@"CHANGETABRINDENX" object:nil];
        
        [self dismissViewControllerClass:[UITabBarController class]];
        
    });
  
    
    
}

- (void)rotateView:(UIImageView *)view iscontrary:(BOOL)isContrary

{
    
    CGFloat pi = isContrary == YES ? -M_PI*2.0 : M_PI*2.0;
     CABasicAnimation *rotationAnimation;
    
     rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    
    rotationAnimation.toValue = [NSNumber numberWithFloat:pi];
    
    rotationAnimation.duration = 1.5;
    
     rotationAnimation.repeatCount = HUGE_VALF;
    
     [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    
}

//停止动画
- (void)stopAnimationWithView:(UIImageView*)view{
    [view.layer removeAllAnimations];
}


- (UIImageView*)bgimgView{
    if (!_bgimgView) {
        _bgimgView = [[UIImageView alloc]init];
    }
    return _bgimgView;
}

- (UIImageView*)smallcircle{
    if (!_smallcircle) {
        _smallcircle = [[UIImageView alloc]init];
    }
    return _smallcircle;
}

- (UIImageView*)centrecircle{
    if (!_centrecircle) {
        _centrecircle = [[UIImageView alloc]init];
    }
    return _centrecircle;
}

- (UIImageView*)bigcircle{
    if (!_bigcircle) {
        _bigcircle = [[UIImageView alloc]init];
    }
    return _bigcircle;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
